'use client'
import React from 'react'
import { useRouter } from 'next/navigation';
import { createThrottledFunction } from '@/app/utils/createThrottledFunction';


interface ButtonProps {
  title?: string;
  style?: string;
  type?: 'login' | 'register' | 'default';
  onClick?: () => void;
}

export default function Button(props: ButtonProps) {
    const { title, style, type, onClick } = props;
    const router = useRouter();
    const handleClick = createThrottledFunction(() => {
      console.log('click');
      if (type === 'login') {
        router.push('/login');
      }
      if (type === 'register') {
        router.push('/register');
      }
      if (onClick) {
        onClick();
      }
    }, 1000);
  return (
    <button className={`bg-blue-500 text-white px-4 py-2 rounded-md ${style}`} onClick={handleClick}>
      {title || "Button"}
    </button>
  )
}